package com.atguigu.eduservice.api;

import com.atguigu.commonutils.R;
import com.atguigu.eduservice.entity.EduChapter;
import com.atguigu.eduservice.entity.EduCourse;
import com.atguigu.eduservice.entity.EduTeacher;
import com.atguigu.eduservice.service.EduCourseService;
import com.atguigu.eduservice.service.EduTeacherService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@Api(description = "前台首页展示")
//@CrossOrigin//跨域
@RestController
@RequestMapping("/eduservice/index")
public class IndexController {
    @Autowired
    private EduCourseService courseService;
    @Autowired
    private EduTeacherService teacherService;

    @ApiOperation(value = "查询首页展示的8门课程及4位讲师")
    @GetMapping("/getCourseTeacher")
    public R getCourseTeacher(){
       //8门课程，状态都是已发布(normal),取最新的
        QueryWrapper<EduCourse>courseWrapper=new QueryWrapper<>();
        courseWrapper.eq("status","Normal");
        courseWrapper.orderByDesc("gmt_create");
        courseWrapper.last("LIMIT 8");
        List<EduCourse> courseList = courseService.list(courseWrapper);
        //4位讲师，取最新
        QueryWrapper<EduTeacher>teacherWrapper=new QueryWrapper<>();
        teacherWrapper.orderByDesc("gmt_create");
        teacherWrapper.last("LIMIT 4");
        List<EduTeacher> teacherList = teacherService.list(teacherWrapper);
        return R.ok().data("courseList",courseList).data("teacherList",teacherList);
    }

}
